# -*- coding:utf-8 -*-
from __future__ import print_function
import sys
sys.path.append('../')
from tools import *

class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        # write code here
        if pHead == None:
        	return None
        formerNode = ListNode(pHead.val)
        if(not pHead.next):
        	return formerNode
        latterNode = ListNode(pHead.next.val)
        latterNode.next = formerNode
        pHead = pHead.next
        while pHead.next:
        	latterNode , formerNode = formerNode,latterNode
        	latterNode = ListNode(pHead.next.val)
        	latterNode.next = formerNode
        	pHead = pHead.next
        return latterNode